package org.grottarossa.ui.core.casemanagement.tasks;


import java.util.ResourceBundle;

import org.grottarossa.ui.core.ApplicationSession;
import org.grottarossa.ui.core.base.BaseForm;
import org.grottarossa.ui.core.i18n.DM;

import com.vaadin.data.util.BeanItem;
import com.vaadin.ui.Field;
import com.vaadin.ui.Form;
import com.vaadin.ui.GridLayout;

public class TaskForm extends BaseForm
{

    /**
	 *
	 */
	private static final long serialVersionUID = -3098007648433354576L;

	ResourceBundle localizer = DM.instance().getBundle(getClass().getName());
	private GridLayout ourLayout;

	 public static final Object[] NATURAL_COL_ORDER = new Object[] {
		 "compito",
         "stato",
         "completato",
         "assegnatoA",
         "scadenza"};

	 public static final String[] COL_HEADERS_ENGLISH = new String[] {
		 "Compito",
         "Stato",
         "Completato",
         "AssegnatoA",
         "Scadenza"};

    public TaskForm(ApplicationSession appSession, BeanItem<TaskLess> Task)
    {
    	super(appSession);
    	ourLayout = new GridLayout(2, 3);
        ourLayout.setMargin(true, true, false, false);
        ourLayout.setSpacing(true);
        setLayout(ourLayout);

        setWriteThrough(false);
        setInvalidCommitted(false);

        setFormFieldFactory(new TaskFormFactory(m_appSession));
        setItemDataSource(Task);

        setVisibleItemProperties(TaskForm.NATURAL_COL_ORDER);
        setSizeUndefined();
    }

    @Override
    protected void attachField(Object propertyId, Field field)
    {
        if (propertyId.equals("compito")) {
            ourLayout.addComponent(field, 0, 0);
        } else if (propertyId.equals("stato")) {
            ourLayout.addComponent(field, 1, 0);
        } else if (propertyId.equals("completato")) {
            ourLayout.addComponent(field, 0, 1);
        } else if (propertyId.equals("assegnatoA")) {
            ourLayout.addComponent(field, 1, 1);
        } else if (propertyId.equals("scadenza")) {
            ourLayout.addComponent(field, 0, 2);
        }
    }
}
